const util = require('util')

class DepWebpackPlugin {
  apply(compiler) {
    compiler.hooks.normalModuleFactory.tap('DepWebpackPlugin', (normalModuleFactory) => {
      normalModuleFactory.hooks.beforeResolve.tapAsync('DepWebpackPlugin', (resolveData, callback) => {
        if(resolveData.dependencyType == 'esm' && resolveData.contextInfo.issuer != '') {
          debugger
          console.log(1111, resolveData);
        }
        callback()
      })

      normalModuleFactory.hooks.resolve.tapAsync('DepWebpackPlugin', (resolveData, callback) => {
        if(resolveData.dependencyType == 'esm' && resolveData.contextInfo.issuer != '') {
          debugger
          console.log(1111, resolveData);
        }
        callback()
      })

      normalModuleFactory.hooks.afterResolve.tapAsync('DepWebpackPlugin', (resolveData, callback) => {
        if(resolveData.dependencyType == 'esm' && resolveData.contextInfo.issuer != '') {
          debugger
          console.log(1111, resolveData);
        }
        callback()
      })
    })
  }
}

module.exports = DepWebpackPlugin